package com.qst.service.ssm;

import com.qst.ExamException;
import com.qst.dao.DAOFactory;
import com.qst.dao.TeamDao;
import com.qst.dao.TestPersonnelDAO;
import com.qst.entity.Team;
import com.qst.entity.TestPersonnel;
import com.qst.mapper.TeamMapper;
import com.qst.mapper.TestPersonnelMapper;
import com.qst.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;
@Service
public class TeamServiceSsmImpl implements TeamService {

    @Autowired
    private TeamMapper teamMapper;

    @Autowired
    private TestPersonnelMapper testPersonnelMapper;

    @Override
    public List<Team> findByCreator(Integer creator_id) {
        return teamMapper.findByCreator(creator_id);
    }

    @Override
    public List<Team> findAll() {
        return teamMapper.findAll();
    }

    @Override
    public Team findById(Integer id) {
        return teamMapper.findById(id);
    }

    @Override
    public void saveTeam(Team t) {
        teamMapper.insert(t);
    }

    @Override
    public void updateTeam(Team t) {
        teamMapper.update(t);
    }

    @Override
    public void deleteTeam(int id) {
        List<TestPersonnel> personnels = testPersonnelMapper.findByTeam(id);
        if (personnels.size() > 0) {
            throw new ExamException("有参测人员的批次不能删除");
        }
        teamMapper.delete(id);
    }
}
